package br.com.fidalgotecnologia.layar.json;

import org.json.JSONException;
import org.json.JSONObject;

import br.com.fidalgotecnologia.layar.entity.Anchor;

public class AnchorJson {
	 private Anchor anchor;
	    private JSONObject json;
	    
	    public AnchorJson(Anchor anchor){
	    	this.anchor = anchor;
	    	json = new JSONObject();
	    	try {
				if(anchor.getGeolocation()!=null){
					json.put("geolocation", new GeolocationJson(anchor.getGeolocation()).getJson());
				}else if(anchor.getReferenceImage()!=null){
					json.put("referenceImage",anchor.getReferenceImage());
				}
				
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    }
	    
	   public JSONObject getJson() {
		return json;
	}
	    
		@Override
		public String toString() {
			String retorno = null;
			
			try {
				
				retorno = json.toString();
			} catch (Exception  e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return retorno;
		}
	
}
